package com.newu.lh.databinding;

import android.content.Context;
import android.databinding.Bindable;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.PopupWindow;

import java.util.ArrayList;
import java.util.List;

class MAdapter extends BaseAdapter {
    private Context context;
    private List<Bean> mList;
    private ViewDataBinding binding;

    public MAdapter(MainActivity mainActivity, ArrayList<Bean> list) {
        context = mainActivity;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item, viewGroup, false);
            view = binding.getRoot();
            view.setTag(binding);
        } else {
            binding = (ViewDataBinding) view.getTag();
        }
        binding.setVariable(com.newu.lh.databinding.BR.bean, mList.get(i));
        return view;
    }
}
